<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新增供应商</title>
<jsp:include page="../../import.jsp" flush="true" />
<style>
#starDt #endDt{
	width : 120px !important;
}
</style>
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div id="pageInTab" class="pageInTab">
				<form id="formSet1_splProtocolAdd">
				
					<c:if test="${isModify == 1 }">
						<div class="fieldset1 tabel_col clearFix">
							<div class="caption">
								<span class="title">资料信息</span>
							</div>
							<div class="fieldBox col_100_auto">
								<div class="label">承诺协议有效期</div>
								<div class="field">
											<input ligerui="width: 180" name="startDt"
												id="startDt" type="text" class="ui-datepicker" value=""
												validate="{required:true}"> - <input
												ligerui="width: 180" name="endDt" id="endDt"
												type="text" class="ui-datepicker" value=""
												validate="{required:true}">
								</div>
							</div>
	
							<div class="fieldBox col_100">
								<div class="label">附件上传</div>
								<div class="field">
			                           <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload3.jsp" flush="true" >
			                               <jsp:param name="filePath" value="shop/renewProtocol"/>
			                           </jsp:include>
					               <span id="saveBtn" class="sq-button sq-button-round">保存</span>
								</div>
							</div>
						</div>
					</c:if>
					
					<div id="ligergridDB" class="sq-grid"></div>
					
				</form>
		</div>
	</div>
<script type="text/javascript">
//展示附件
function showAttachment(path){
	if (!path)return;
	window.open(path);
}

//详情
function showDetail(_id,_splAttrCd){
	if(!_id)return;
	parent.parent.mainApp.f_addTab('PrdSpl_3'+_id,'供应商详情','<%=path%>/product/splInfo/toDetailPage.do?id='+_id+'&splAttrCd='+_splAttrCd);
}
$(function(){
	var splId = ${splId};
	var gridDB = null;
	var oldGridDB = null;
	var dataId = null;
	
	//初始化详情数据
	//initData(); 
	//初始化人员信息
	//initSplRlGrid();
	
	initGridDB(); //初始化待办列表
	
	
	
	//初始化列表
	function initGridDB() {
		$("#ligergridDB").ligerGrid({
			url : '<%=path%>/spl/splReProtocol/initList.do?splId=' + splId + '&isNew=2',
			method : 'get',
			columns : [
				{
					display : '供应商名称',
					name : '',
					width : 200,
					enabledSort : false,
					render: function(rowdata, rowindex, value){
						var h='<a href="javascript:showDetail(';
	            		h+="'"+rowdata.splId+"'";
		                if(StringUtils.isNotEmpty(rowdata.splAttrCd)){
			                h+=",'"+rowdata.splAttrCd+"'";
		                }else{
			                h+=",''";
		                }
	                    h+=')">'+rowdata.splNm+'</a>';
	                	return h;
					}
				},
				{
					display : '承诺协议有效期',
					name : '',
					width : 200,
					enabledSort : false,
					render: function(rowdata, rowindex, value){
						//return rowdata.protocolStartTm + '-' + rowdata.protocolEndTm ;
						return renderDate(rowdata.protocolStartTm, 'yyyy-MM-dd')
								+ '  ~  ' +
								renderDate(rowdata.protocolEndTm, 'yyyy-MM-dd');
					}
				},
				{
					display : '上传文件名',
					name : 'fileNm',
					minWidth : 100,
					enabledSort : false,
					render: function(rowdata, rowindex, value){
						var a = '<a href="javascript:showAttachment(\''+rowdata.filePath+'\')">' + rowdata.fileNm +'</a>';
						return a ;
					}
				},
				{
					display : '上传者',
					name : 'crtUsrNm',
					minWidth : 100,
					enabledSort : false
				},
				{
					display : '上传时间',
					name : 'crtTm',
					minWidth : 150,
					enabledSort : false,
					render: function(rowdata, rowindex, value){
						if (value){
							return renderDate(value);
						}
					}
				},
				{
					display : '生效时间',
					name : 'effectiveTm',
					minWidth : 100,
					enabledSort : false
				},
			],
			pageSize : 10,
			pageSizeOptions : [ 10, 20, 30, 40, 50, 100 ], //按照自己的喜好选择不同的页面显示条数
			root : 'rows',
			record : 'total',
			hideLoadButton : true,
			width : '100%',
			height : '45%',
			//heightDiff : -30,
			//checkbox : true,
			rownumbers : true,
			onAfterShowData : function() {
				$(".gridTip").grid_ligerTip();
				SetIframe_height();
			},
			onLoaded : function (grid) {
				console.log(grid);
				grid.toggleLoading(null);
				console.log(grid.data.total);
				if (grid.data.rows[0]) {
					console.log(grid.data.rows[0].id);
					dataId = grid.data.rows[0].id
				}
			}
		});
		gridDB = liger.get("ligergridDB");
		gridDB.setHeight(100);
		gridDB.options.isSingleCheck = true;
	}
	
	var formSet1 = $('#formSet1_splProtocolAdd').ligerForm({
        validate : true
	});
	
	// 添加记录并上传附件
		$('#saveBtn').click(function(){
			//alert();
			var form = new liger.get('formSet1_splProtocolAdd');
			if (!form.valid()) {
				top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
				return;
			}
			var data = form.getData();
			var fileParams = getUploadResultParams(); //获取附件上传的信息
			if (JSON.stringify(fileParams) == "[]") {
				top.$.ligerDialog.SQalert({content: "请先上传附件",SQ_type: "warning"});
				return;
			}
			console.log(fileParams[0].filePath);
	        //data["fileParams"] = JSON.stringify(fileParams);
	        data["filePath"] = fileParams[0].filePath;
	        data["fileNm"] = fileParams[0].fileNm;
			data["splId"] = splId;
			data["dataId"] = dataId;
			console.log(data);
			$.ajax({
				type : 'post',
				dataType : 'json',
				data : data,
				url : '<%=path%>/spl/splReProtocol/add.do',
				success : function(msg) {
					if (msg.success == 1) {
						console.log(msg);
						gridDB.reload();
					} else {
						$.ligerDialog.SQalert({
							content : msg.info,
							SQ_type : "error"
						});
					}
				}
			});
		});
	
	//格式化时间
	function renderDate(value, formatStr) {
		var dateStr = "";
		if (!formatStr) formatStr = "yyyy-MM-dd hh:mm"
		if (null != value) {
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, formatStr);
		}
		return dateStr;
	}

});
<%-- jquery==end--%>
	
<%-- function==start--%>



<%--function==end--%>
</script>
</body>
</html>
